package com.gitee.feizns.quickstart.ding.talk.api.top.api.smart.work.hrm.employee;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiSmartworkHrmEmployeeFieldGrouplistRequest;
import com.dingtalk.api.response.OapiSmartworkHrmEmployeeFieldGrouplistResponse;
import com.gitee.feizns.quickstart.ding.talk.utils.Utils;
import com.taobao.api.ApiException;

import java.util.List;

/**
 * 获取花名册字段组详情（/topapi/smartwork/hrm/employee/field/grouplist）
 * 接口路径：<a href="https://open.dingtalk.com/document/orgapp/intelligent-personnel-update-employee-file-information">获取花名册字段组详情（/topapi/smartwork/hrm/employee/field/grouplist）</a>
 * @link <a href="https://open.dingtalk.com/document/orgapp/intelligent-personnel-update-employee-file-information">服务端API 智能人事 花名册 获取花名册字段组详情</a>
 * @author feizns
 * @since 2024/6/29
 */
public class FieldGroupList {

    /**
     * 获取花名册字段组详情
     * 获取花名册字段组详情（/topapi/smartwork/hrm/employee/field/grouplist）
     * @param accessToken 访问令牌
     * @param agentId 代理 ID
     * @return {@link List }<{@link OapiSmartworkHrmEmployeeFieldGrouplistResponse.GroupMetaInfo }>
     * @throws ApiException API 异常
     */
    public static List<OapiSmartworkHrmEmployeeFieldGrouplistResponse.GroupMetaInfo> execute(String accessToken, Long agentId) throws ApiException {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/field/grouplist");
        OapiSmartworkHrmEmployeeFieldGrouplistRequest req = new OapiSmartworkHrmEmployeeFieldGrouplistRequest();
        req.setAgentid(agentId);
        OapiSmartworkHrmEmployeeFieldGrouplistResponse rsp = client.execute(req, accessToken);
        return Utils.ifErrorThrow(rsp).getResult();
    }

}
